package top.bug.blog.controller.backend;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import top.bug.blog.annotation.Auth;
import top.bug.blog.common.Result;
import top.bug.blog.service.SysConfigService;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 * @description 后台-系统配置
 */
@Api(tags = "系统配置模块")
@RestController
@RequestMapping("/configApi")
@Auth
public class SysConfigController {

    @Resource
    private SysConfigService sysConfigService;

    @GetMapping("/getAll")
    @ApiOperation("获取所有配置")
    public Result<Map<String, String>> getAllConfigs() {
        return Result.success(sysConfigService.getAllConfigs());
    }

    @PostMapping("/update")
    @ApiOperation("批量更新配置")
    public Result<Boolean> updateConfigs(@RequestBody Map<String, String> configMap) {
        sysConfigService.updateConfigs(configMap);
        return Result.success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获取单个配置")
    public Result<String> getConfigValue(String key) {
        return Result.success(sysConfigService.getConfigValue(key));
    }
}